{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Slightly modified from https://nbviewer.jupyter.org/github/jaroslavhrdina/brno/blob/master/plane_solve.ipynb and https://nbviewer.jupyter.org/github/jaroslavhrdina/brno/blob/master/plane1_final.ipynb :"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy import *\n",
    "from galgebra.ga import Ga\n",
    "from galgebra.printer import Format\n",
    "Format()\n",
    "import math\n",
    "import sympy as sym"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "cga3d = Ga(r'e_1 e_2 e_3 e e_{0}',g='1 0 0 0 0,0 1 0 0 0,0 0 1 0 0,0 0 0 0 -1,0 0 0 -1 0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left[\\begin{matrix}1 & 0 & 0 & 0 & 0\\\\0 & 1 & 0 & 0 & 0\\\\0 & 0 & 1 & 0 & 0\\\\0 & 0 & 0 & 0 & -1\\\\0 & 0 & 0 & -1 & 0\\end{matrix}\\right]$$"
      ],
      "text/plain": [
       " \\left [ \\begin{array}{ccccc} 1 & 0 & 0 & 0 & 0  \\\\ 0 & 1 & 0 & 0 & 0  \\\\ 0 & 0 & 1 & 0 & 0  \\\\ 0 & 0 & 0 & 0 & -1  \\\\ 0 & 0 & 0 & -1 & 0  \\end{array}\\right ] "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cga3d.g"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "e1,e2,e3,eo,eoo = cga3d.mv()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def pt(arg): # R^3 vector --> conformal point. \n",
    "    if isinstance(arg,str):           # Return general 3D point\n",
    "        v = cga3d.mv(arg, 'vector')     # General conformal vector \n",
    "        v = v + (v < eoo)*eo + (v < eo)*eoo  # 3D part \n",
    "        v = eo + v + (v<v)*eoo/2\n",
    "    elif arg == 0:\n",
    "        v = eo\n",
    "    elif (arg < eoo) == 0:    # Return point for 3D vector in arg\n",
    "        v = eo + arg + (arg<arg)*eoo/2\n",
    "    else: v = arg     # arg already in conformal representation   \n",
    "    return(v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "ax = sym.Symbol('a_x')\n",
    "ay = sym.Symbol('a_y')\n",
    "az = sym.Symbol('a_z')\n",
    "\n",
    "a = ax*e1+ay*e2+az*e3\n",
    "\n",
    "cx = sym.Symbol('c_x')\n",
    "cy = sym.Symbol('c_y')\n",
    "cz = sym.Symbol('c_z')\n",
    "\n",
    "c = cx*e1+cy*e2+cz*e3\n",
    "\n",
    "sx = sym.Symbol('s_x')\n",
    "sy = sym.Symbol('s_y')\n",
    "sz = sym.Symbol('s_z')\n",
    "\n",
    "s = sx*e1+sy*e2+sz*e3\n",
    "\n",
    "x = sym.Symbol('x')\n",
    "\n",
    "nx = sy\n",
    "ny = -sx\n",
    "nz = 0\n",
    "\n",
    "n = nx*e1+ny*e2+nz*e3\n",
    "\n",
    "I = e1^e2^e3\n",
    "II = e1^e2^e3^eo^eoo\n",
    "A = pt(a)\n",
    "C = pt(c)\n",
    "S = pt(a + s)\n",
    "N = pt(a + n)\n",
    "\n",
    "m = I*(s^n)\n",
    "M = pt(a + m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "plane_1 =((A^M^S^eoo))\n",
    "plane_2 =((A^C^S^eoo))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "EQ=(plane_1<plane_2)\n",
    "E1=(plane_1<plane_1)\n",
    "E2=(plane_2<plane_2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy.solvers import solve\n",
    "import sympy as sym\n",
    "from sympy  import Symbol"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} - a_{x} {\\left ( s_{x} \\right )}^{3} s_{z} - a_{x} s_{x} {\\left ( s_{y} \\right )}^{2} s_{z} - a_{x} s_{x} {\\left ( s_{z} \\right )}^{3} - a_{y} {\\left ( s_{x} \\right )}^{2} s_{y} s_{z} - a_{y} {\\left ( s_{y} \\right )}^{3} s_{z} - a_{y} s_{y} {\\left ( s_{z} \\right )}^{3} + a_{z} {\\left ( s_{x} \\right )}^{4} + 2 a_{z} {\\left ( s_{x} \\right )}^{2} {\\left ( s_{y} \\right )}^{2} + a_{z} {\\left ( s_{x} \\right )}^{2} {\\left ( s_{z} \\right )}^{2} + a_{z} {\\left ( s_{y} \\right )}^{4} + a_{z} {\\left ( s_{y} \\right )}^{2} {\\left ( s_{z} \\right )}^{2} + c_{x} {\\left ( s_{x} \\right )}^{3} s_{z} + c_{x} s_{x} {\\left ( s_{y} \\right )}^{2} s_{z} + c_{x} s_{x} {\\left ( s_{z} \\right )}^{3} + c_{y} {\\left ( s_{x} \\right )}^{2} s_{y} s_{z} + c_{y} {\\left ( s_{y} \\right )}^{3} s_{z} + c_{y} s_{y} {\\left ( s_{z} \\right )}^{3} - c_{z} {\\left ( s_{x} \\right )}^{4} - 2 c_{z} {\\left ( s_{x} \\right )}^{2} {\\left ( s_{y} \\right )}^{2} - c_{z} {\\left ( s_{x} \\right )}^{2} {\\left ( s_{z} \\right )}^{2} - c_{z} {\\left ( s_{y} \\right )}^{4} - c_{z} {\\left ( s_{y} \\right )}^{2} {\\left ( s_{z} \\right )}^{2} \\end{equation*}"
      ],
      "text/plain": [
       "- a_{x} {\\left ( s_{x} \\right )}^{3} s_{z} - a_{x} s_{x} {\\left ( s_{y} \\right )}^{2} s_{z} - a_{x} s_{x} {\\left ( s_{z} \\right )}^{3} - a_{y} {\\left ( s_{x} \\right )}^{2} s_{y} s_{z} - a_{y} {\\left ( s_{y} \\right )}^{3} s_{z} - a_{y} s_{y} {\\left ( s_{z} \\right )}^{3} + a_{z} {\\left ( s_{x} \\right )}^{4} + 2 a_{z} {\\left ( s_{x} \\right )}^{2} {\\left ( s_{y} \\right )}^{2} + a_{z} {\\left ( s_{x} \\right )}^{2} {\\left ( s_{z} \\right )}^{2} + a_{z} {\\left ( s_{y} \\right )}^{4} + a_{z} {\\left ( s_{y} \\right )}^{2} {\\left ( s_{z} \\right )}^{2} + c_{x} {\\left ( s_{x} \\right )}^{3} s_{z} + c_{x} s_{x} {\\left ( s_{y} \\right )}^{2} s_{z} + c_{x} s_{x} {\\left ( s_{z} \\right )}^{3} + c_{y} {\\left ( s_{x} \\right )}^{2} s_{y} s_{z} + c_{y} {\\left ( s_{y} \\right )}^{3} s_{z} + c_{y} s_{y} {\\left ( s_{z} \\right )}^{3} - c_{z} {\\left ( s_{x} \\right )}^{4} - 2 c_{z} {\\left ( s_{x} \\right )}^{2} {\\left ( s_{y} \\right )}^{2} - c_{z} {\\left ( s_{x} \\right )}^{2} {\\left ( s_{z} \\right )}^{2} - c_{z} {\\left ( s_{y} \\right )}^{4} - c_{z} {\\left ( s_{y} \\right )}^{2} {\\left ( s_{z} \\right )}^{2}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "EQ"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$- a_{x} s_{x}^{3} s_{z} - a_{x} s_{x} s_{y}^{2} s_{z} - a_{x} s_{x} s_{z}^{3} - a_{y} s_{x}^{2} s_{y} s_{z} - a_{y} s_{y}^{3} s_{z} - a_{y} s_{y} s_{z}^{3} + a_{z} s_{x}^{4} + 2 a_{z} s_{x}^{2} s_{y}^{2} + a_{z} s_{x}^{2} s_{z}^{2} + a_{z} s_{y}^{4} + a_{z} s_{y}^{2} s_{z}^{2} + c_{x} s_{x}^{3} s_{z} + c_{x} s_{x} s_{y}^{2} s_{z} + c_{x} s_{x} s_{z}^{3} + c_{y} s_{x}^{2} s_{y} s_{z} + c_{y} s_{y}^{3} s_{z} + c_{y} s_{y} s_{z}^{3} - c_{z} s_{x}^{4} - 2 c_{z} s_{x}^{2} s_{y}^{2} - c_{z} s_{x}^{2} s_{z}^{2} - c_{z} s_{y}^{4} - c_{z} s_{y}^{2} s_{z}^{2}$$"
      ],
      "text/plain": [
       "       3                2                3         2                  3       \n",
       "- aₓ⋅sₓ ⋅s_z - aₓ⋅sₓ⋅s_y ⋅s_z - aₓ⋅sₓ⋅s_z  - a_y⋅sₓ ⋅s_y⋅s_z - a_y⋅s_y ⋅s_z - \n",
       "\n",
       "           3         4           2    2         2    2          4          2  \n",
       "a_y⋅s_y⋅s_z  + a_z⋅sₓ  + 2⋅a_z⋅sₓ ⋅s_y  + a_z⋅sₓ ⋅s_z  + a_z⋅s_y  + a_z⋅s_y ⋅s\n",
       "\n",
       "  2        3                2                3         2                  3   \n",
       "_z  + cₓ⋅sₓ ⋅s_z + cₓ⋅sₓ⋅s_y ⋅s_z + cₓ⋅sₓ⋅s_z  + c_y⋅sₓ ⋅s_y⋅s_z + c_y⋅s_y ⋅s_\n",
       "\n",
       "               3         4           2    2         2    2          4         \n",
       "z + c_y⋅s_y⋅s_z  - c_z⋅sₓ  - 2⋅c_z⋅sₓ ⋅s_y  - c_z⋅sₓ ⋅s_z  - c_z⋅s_y  - c_z⋅s_\n",
       "\n",
       " 2    2\n",
       "y ⋅s_z "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "EQ.obj"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left [ \\frac{- a_{y} s_{y} s_{z} + a_{z} s_{x}^{2} + a_{z} s_{y}^{2} + c_{x} s_{x} s_{z} + c_{y} s_{y} s_{z} - c_{z} s_{x}^{2} - c_{z} s_{y}^{2}}{s_{x} s_{z}}\\right ]$$"
      ],
      "text/plain": [
       "⎡                     2          2                                   2        \n",
       "⎢-a_y⋅s_y⋅s_z + a_z⋅sₓ  + a_z⋅s_y  + cₓ⋅sₓ⋅s_z + c_y⋅s_y⋅s_z - c_z⋅sₓ  - c_z⋅s\n",
       "⎢─────────────────────────────────────────────────────────────────────────────\n",
       "⎣                                     sₓ⋅s_z                                  \n",
       "\n",
       "  2⎤\n",
       "_y ⎥\n",
       "───⎥\n",
       "   ⎦"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solve(EQ.obj, ax)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left [ - \\operatorname{acos}{\\left (- \\left(s_{x}^{2} + s_{y}^{2} + s_{z}^{2}\\right) \\left(a_{x} s_{x} s_{z} + a_{y} s_{y} s_{z} - a_{z} s_{x}^{2} - a_{z} s_{y}^{2} - c_{x} s_{x} s_{z} - c_{y} s_{y} s_{z} + c_{z} s_{x}^{2} + c_{z} s_{y}^{2}\\right) \\right )} + 2 \\pi, \\quad \\operatorname{acos}{\\left (- \\left(s_{x}^{2} + s_{y}^{2} + s_{z}^{2}\\right) \\left(a_{x} s_{x} s_{z} + a_{y} s_{y} s_{z} - a_{z} s_{x}^{2} - a_{z} s_{y}^{2} - c_{x} s_{x} s_{z} - c_{y} s_{y} s_{z} + c_{z} s_{x}^{2} + c_{z} s_{y}^{2}\\right) \\right )}\\right ]$$"
      ],
      "text/plain": [
       "⎡      ⎛ ⎛  2      2      2⎞ ⎛                                2          2    \n",
       "⎣- acos⎝-⎝sₓ  + s_y  + s_z ⎠⋅⎝aₓ⋅sₓ⋅s_z + a_y⋅s_y⋅s_z - a_z⋅sₓ  - a_z⋅s_y  - c\n",
       "\n",
       "                               2          2⎞⎞            ⎛ ⎛  2      2      2⎞\n",
       "ₓ⋅sₓ⋅s_z - c_y⋅s_y⋅s_z + c_z⋅sₓ  + c_z⋅s_y ⎠⎠ + 2⋅π, acos⎝-⎝sₓ  + s_y  + s_z ⎠\n",
       "\n",
       " ⎛                                2          2                                \n",
       "⋅⎝aₓ⋅sₓ⋅s_z + a_y⋅s_y⋅s_z - a_z⋅sₓ  - a_z⋅s_y  - cₓ⋅sₓ⋅s_z - c_y⋅s_y⋅s_z + c_z\n",
       "\n",
       "   2          2⎞⎞⎤\n",
       "⋅sₓ  + c_z⋅s_y ⎠⎠⎦"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solve(sym.cos(x) - EQ.obj, x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left [ - \\operatorname{acos}{\\left (a_{x} s_{x} \\right )} + 2 \\pi, \\quad \\operatorname{acos}{\\left (a_{x} s_{x} \\right )}\\right ]$$"
      ],
      "text/plain": [
       "[-acos(aₓ⋅sₓ) + 2⋅π, acos(aₓ⋅sₓ)]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solve(sym.cos(x) - ax*sx, x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy.solvers import solve\n",
    "import sympy as sym\n",
    "from sympy  import Symbol"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "EQQ=EQ.subs({ax:10, ay: 24, az: 20,cx:10, cy: 26, cz: 20,sx:10, sy:11, sz: 20})\n",
    "E1Q=E1.subs({ax:10, ay: 24, az: 20,cx:10, cy: 26, cz: 20,sx:10, sy:11, sz: 20})\n",
    "E2Q=E2.subs({ax:10, ay: 24, az: 20,cx:10, cy: 26, cz: 20,sx:10, sy:11, sz: 20})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} \\frac{11}{6862050} \\end{equation*}"
      ],
      "text/plain": [
       "\\frac{11}{6862050}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "EQQ/(E1Q*E2Q)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$1.57079472377539$$"
      ],
      "text/plain": [
       "1.57079472377539"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sym.acos(float(11/6862050))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A rewritten version:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy import *\n",
    "from galgebra.ga import Ga\n",
    "from galgebra.printer import Format\n",
    "Format()\n",
    "import math\n",
    "import sympy as sym"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "cga3d = Ga(r'e_x e_y e_z e_{0} e_{\\infty}',g='1 0 0 0 0,0 1 0 0 0,0 0 1 0 0,0 0 0 0 -1,0 0 0 -1 0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "e_x,e_y,e_z,e_0,e_oo = cga3d.mv()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*}  \\boldsymbol{e}_{x} \\end{equation*}"
      ],
      "text/plain": [
       " \\boldsymbol{e}_{x}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "e_x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*}  \\boldsymbol{e}_{y} \\end{equation*}"
      ],
      "text/plain": [
       " \\boldsymbol{e}_{y}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "e_y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*}  \\boldsymbol{e}_{z} \\end{equation*}"
      ],
      "text/plain": [
       " \\boldsymbol{e}_{z}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "e_z"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*}  \\boldsymbol{e}_{{0}} \\end{equation*}"
      ],
      "text/plain": [
       " \\boldsymbol{e}_{{0}}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "e_0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*}  \\boldsymbol{e}_{{\\infty}} \\end{equation*}"
      ],
      "text/plain": [
       " \\boldsymbol{e}_{{\\infty}}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "e_oo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def pt(arg): # R^3 vector --> conformal point. \n",
    "    if isinstance(arg,str):           # Return general 3D point\n",
    "        v = cga3d.mv(arg, 'vector')     # General conformal vector \n",
    "        v = v + (v < e_oo)*e_0 + (v < e_0)*e_oo  # 3D part \n",
    "        v = e_0 + v + (v<v)*e_oo/2\n",
    "    elif arg == 0:\n",
    "        v = e_0\n",
    "    elif (arg < e_oo) == 0:    # Return point for 3D vector in arg\n",
    "        v = e_0 + arg + (arg<arg)*e_oo/2\n",
    "    else: v = arg     # arg already in conformal representation   \n",
    "    return(v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "def point(v_name, v_x=None, v_y=None, v_z=None):\n",
    "    v_x_name = '%s_x' % v_name\n",
    "    v_y_name = '%s_y' % v_name\n",
    "    v_z_name = '%s_z' % v_name\n",
    "    v_x = sym.Symbol(v_x_name) if v_x is None else v_x\n",
    "    v_y = sym.Symbol(v_y_name) if v_y is None else v_y\n",
    "    v_z = sym.Symbol(v_z_name) if v_z is None else v_z\n",
    "    v = v_x * e_x + v_y * e_y + v_z * e_z\n",
    "    return {v_name: v, v_x_name: v_x, v_y_name: v_y, v_z_name: v_z}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "def vector(v_name, v_x, v_y, y_z):\n",
    "    v_x_name = '%s_x' % v_name\n",
    "    v_y_name = '%s_y' % v_name\n",
    "    v_z_name = '%s_z' % v_name\n",
    "    v = v_x * e_x + v_y * e_y + v_z * e_z\n",
    "    return {v_name: v, v_x_name: v_x, v_y_name: v_y, v_z_name: v_z}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "locals().update(point('a'))\n",
    "A = pt(a)\n",
    "\n",
    "locals().update(point('c'))\n",
    "C = pt(c)\n",
    "\n",
    "locals().update(point('s'))\n",
    "S = pt(s)\n",
    "\n",
    "locals().update(point('n', s_y, -s_x, 0))\n",
    "\n",
    "I = e_x^e_y^e_z\n",
    "II = e_x^e_y^e_z^e_0^e_oo\n",
    "A = pt(a)\n",
    "C = pt(c)\n",
    "S = pt(a + s)\n",
    "N = pt(a + n)\n",
    "\n",
    "m = I*(s^n)\n",
    "M = pt(a + m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = sym.Symbol('x')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "plane_1 =((A^M^S^e_oo))\n",
    "plane_2 =((A^C^S^e_oo))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "EQ=(plane_1<plane_2)\n",
    "E1=(plane_1<plane_1)\n",
    "E2=(plane_2<plane_2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy.solvers import solve\n",
    "import sympy as sym\n",
    "from sympy  import Symbol"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} - a_{x} {\\left ( s_{x} \\right )}^{3} s_{z} - a_{x} s_{x} {\\left ( s_{y} \\right )}^{2} s_{z} - a_{x} s_{x} {\\left ( s_{z} \\right )}^{3} - a_{y} {\\left ( s_{x} \\right )}^{2} s_{y} s_{z} - a_{y} {\\left ( s_{y} \\right )}^{3} s_{z} - a_{y} s_{y} {\\left ( s_{z} \\right )}^{3} + a_{z} {\\left ( s_{x} \\right )}^{4} + 2 a_{z} {\\left ( s_{x} \\right )}^{2} {\\left ( s_{y} \\right )}^{2} + a_{z} {\\left ( s_{x} \\right )}^{2} {\\left ( s_{z} \\right )}^{2} + a_{z} {\\left ( s_{y} \\right )}^{4} + a_{z} {\\left ( s_{y} \\right )}^{2} {\\left ( s_{z} \\right )}^{2} + c_{x} {\\left ( s_{x} \\right )}^{3} s_{z} + c_{x} s_{x} {\\left ( s_{y} \\right )}^{2} s_{z} + c_{x} s_{x} {\\left ( s_{z} \\right )}^{3} + c_{y} {\\left ( s_{x} \\right )}^{2} s_{y} s_{z} + c_{y} {\\left ( s_{y} \\right )}^{3} s_{z} + c_{y} s_{y} {\\left ( s_{z} \\right )}^{3} - c_{z} {\\left ( s_{x} \\right )}^{4} - 2 c_{z} {\\left ( s_{x} \\right )}^{2} {\\left ( s_{y} \\right )}^{2} - c_{z} {\\left ( s_{x} \\right )}^{2} {\\left ( s_{z} \\right )}^{2} - c_{z} {\\left ( s_{y} \\right )}^{4} - c_{z} {\\left ( s_{y} \\right )}^{2} {\\left ( s_{z} \\right )}^{2} \\end{equation*}"
      ],
      "text/plain": [
       "- a_{x} {\\left ( s_{x} \\right )}^{3} s_{z} - a_{x} s_{x} {\\left ( s_{y} \\right )}^{2} s_{z} - a_{x} s_{x} {\\left ( s_{z} \\right )}^{3} - a_{y} {\\left ( s_{x} \\right )}^{2} s_{y} s_{z} - a_{y} {\\left ( s_{y} \\right )}^{3} s_{z} - a_{y} s_{y} {\\left ( s_{z} \\right )}^{3} + a_{z} {\\left ( s_{x} \\right )}^{4} + 2 a_{z} {\\left ( s_{x} \\right )}^{2} {\\left ( s_{y} \\right )}^{2} + a_{z} {\\left ( s_{x} \\right )}^{2} {\\left ( s_{z} \\right )}^{2} + a_{z} {\\left ( s_{y} \\right )}^{4} + a_{z} {\\left ( s_{y} \\right )}^{2} {\\left ( s_{z} \\right )}^{2} + c_{x} {\\left ( s_{x} \\right )}^{3} s_{z} + c_{x} s_{x} {\\left ( s_{y} \\right )}^{2} s_{z} + c_{x} s_{x} {\\left ( s_{z} \\right )}^{3} + c_{y} {\\left ( s_{x} \\right )}^{2} s_{y} s_{z} + c_{y} {\\left ( s_{y} \\right )}^{3} s_{z} + c_{y} s_{y} {\\left ( s_{z} \\right )}^{3} - c_{z} {\\left ( s_{x} \\right )}^{4} - 2 c_{z} {\\left ( s_{x} \\right )}^{2} {\\left ( s_{y} \\right )}^{2} - c_{z} {\\left ( s_{x} \\right )}^{2} {\\left ( s_{z} \\right )}^{2} - c_{z} {\\left ( s_{y} \\right )}^{4} - c_{z} {\\left ( s_{y} \\right )}^{2} {\\left ( s_{z} \\right )}^{2}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "EQ"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$- a_{x} s_{x}^{3} s_{z} - a_{x} s_{x} s_{y}^{2} s_{z} - a_{x} s_{x} s_{z}^{3} - a_{y} s_{x}^{2} s_{y} s_{z} - a_{y} s_{y}^{3} s_{z} - a_{y} s_{y} s_{z}^{3} + a_{z} s_{x}^{4} + 2 a_{z} s_{x}^{2} s_{y}^{2} + a_{z} s_{x}^{2} s_{z}^{2} + a_{z} s_{y}^{4} + a_{z} s_{y}^{2} s_{z}^{2} + c_{x} s_{x}^{3} s_{z} + c_{x} s_{x} s_{y}^{2} s_{z} + c_{x} s_{x} s_{z}^{3} + c_{y} s_{x}^{2} s_{y} s_{z} + c_{y} s_{y}^{3} s_{z} + c_{y} s_{y} s_{z}^{3} - c_{z} s_{x}^{4} - 2 c_{z} s_{x}^{2} s_{y}^{2} - c_{z} s_{x}^{2} s_{z}^{2} - c_{z} s_{y}^{4} - c_{z} s_{y}^{2} s_{z}^{2}$$"
      ],
      "text/plain": [
       "       3                2                3         2                  3       \n",
       "- aₓ⋅sₓ ⋅s_z - aₓ⋅sₓ⋅s_y ⋅s_z - aₓ⋅sₓ⋅s_z  - a_y⋅sₓ ⋅s_y⋅s_z - a_y⋅s_y ⋅s_z - \n",
       "\n",
       "           3         4           2    2         2    2          4          2  \n",
       "a_y⋅s_y⋅s_z  + a_z⋅sₓ  + 2⋅a_z⋅sₓ ⋅s_y  + a_z⋅sₓ ⋅s_z  + a_z⋅s_y  + a_z⋅s_y ⋅s\n",
       "\n",
       "  2        3                2                3         2                  3   \n",
       "_z  + cₓ⋅sₓ ⋅s_z + cₓ⋅sₓ⋅s_y ⋅s_z + cₓ⋅sₓ⋅s_z  + c_y⋅sₓ ⋅s_y⋅s_z + c_y⋅s_y ⋅s_\n",
       "\n",
       "               3         4           2    2         2    2          4         \n",
       "z + c_y⋅s_y⋅s_z  - c_z⋅sₓ  - 2⋅c_z⋅sₓ ⋅s_y  - c_z⋅sₓ ⋅s_z  - c_z⋅s_y  - c_z⋅s_\n",
       "\n",
       " 2    2\n",
       "y ⋅s_z "
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "EQ.obj"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left [ \\frac{- a_{y} s_{y} s_{z} + a_{z} s_{x}^{2} + a_{z} s_{y}^{2} + c_{x} s_{x} s_{z} + c_{y} s_{y} s_{z} - c_{z} s_{x}^{2} - c_{z} s_{y}^{2}}{s_{x} s_{z}}\\right ]$$"
      ],
      "text/plain": [
       "⎡                     2          2                                   2        \n",
       "⎢-a_y⋅s_y⋅s_z + a_z⋅sₓ  + a_z⋅s_y  + cₓ⋅sₓ⋅s_z + c_y⋅s_y⋅s_z - c_z⋅sₓ  - c_z⋅s\n",
       "⎢─────────────────────────────────────────────────────────────────────────────\n",
       "⎣                                     sₓ⋅s_z                                  \n",
       "\n",
       "  2⎤\n",
       "_y ⎥\n",
       "───⎥\n",
       "   ⎦"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solve(EQ.obj, a_x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left [ - \\operatorname{acos}{\\left (- \\left(s_{x}^{2} + s_{y}^{2} + s_{z}^{2}\\right) \\left(a_{x} s_{x} s_{z} + a_{y} s_{y} s_{z} - a_{z} s_{x}^{2} - a_{z} s_{y}^{2} - c_{x} s_{x} s_{z} - c_{y} s_{y} s_{z} + c_{z} s_{x}^{2} + c_{z} s_{y}^{2}\\right) \\right )} + 2 \\pi, \\quad \\operatorname{acos}{\\left (- \\left(s_{x}^{2} + s_{y}^{2} + s_{z}^{2}\\right) \\left(a_{x} s_{x} s_{z} + a_{y} s_{y} s_{z} - a_{z} s_{x}^{2} - a_{z} s_{y}^{2} - c_{x} s_{x} s_{z} - c_{y} s_{y} s_{z} + c_{z} s_{x}^{2} + c_{z} s_{y}^{2}\\right) \\right )}\\right ]$$"
      ],
      "text/plain": [
       "⎡      ⎛ ⎛  2      2      2⎞ ⎛                                2          2    \n",
       "⎣- acos⎝-⎝sₓ  + s_y  + s_z ⎠⋅⎝aₓ⋅sₓ⋅s_z + a_y⋅s_y⋅s_z - a_z⋅sₓ  - a_z⋅s_y  - c\n",
       "\n",
       "                               2          2⎞⎞            ⎛ ⎛  2      2      2⎞\n",
       "ₓ⋅sₓ⋅s_z - c_y⋅s_y⋅s_z + c_z⋅sₓ  + c_z⋅s_y ⎠⎠ + 2⋅π, acos⎝-⎝sₓ  + s_y  + s_z ⎠\n",
       "\n",
       " ⎛                                2          2                                \n",
       "⋅⎝aₓ⋅sₓ⋅s_z + a_y⋅s_y⋅s_z - a_z⋅sₓ  - a_z⋅s_y  - cₓ⋅sₓ⋅s_z - c_y⋅s_y⋅s_z + c_z\n",
       "\n",
       "   2          2⎞⎞⎤\n",
       "⋅sₓ  + c_z⋅s_y ⎠⎠⎦"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solve(sym.cos(x) - EQ.obj, x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\left [ - \\operatorname{acos}{\\left (a_{x} s_{x} \\right )} + 2 \\pi, \\quad \\operatorname{acos}{\\left (a_{x} s_{x} \\right )}\\right ]$$"
      ],
      "text/plain": [
       "[-acos(aₓ⋅sₓ) + 2⋅π, acos(aₓ⋅sₓ)]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solve(sym.cos(x) - a_x*s_x, x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy.solvers import solve\n",
    "import sympy as sym\n",
    "from sympy  import Symbol"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "EQQ=EQ.subs({a_x:10, a_y: 24, a_z: 20,c_x:10, c_y: 26, c_z: 20,s_x:10, s_y:11, s_z: 20})\n",
    "E1Q=E1.subs({a_x:10, a_y: 24, a_z: 20,c_x:10, c_y: 26, c_z: 20,s_x:10, s_y:11, s_z: 20})\n",
    "E2Q=E2.subs({a_x:10, a_y: 24, a_z: 20,c_x:10, c_y: 26, c_z: 20,s_x:10, s_y:11, s_z: 20})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} \\frac{11}{6862050} \\end{equation*}"
      ],
      "text/plain": [
       "\\frac{11}{6862050}"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "EQQ/(E1Q*E2Q)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$1.57079472377539$$"
      ],
      "text/plain": [
       "1.57079472377539"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sym.acos(float(11/6862050))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
